package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    //添加
    @PostMapping("/cart/add")
    public ResultInfo addCart(@RequestBody Cart cart){

        Cart cart1 = cartService.addCart(cart);
        return ResultInfo.success(cart1);
    }
    //查看购物车
    @GetMapping("/cart/list")
    public ResultInfo findCartList(){
        List<Cart> cartList = cartService.findCartList();
        return ResultInfo.success(cartList);
    }
    //修改
    @PostMapping("/cart/sub")
    public ResultInfo sub(@RequestBody Cart cart){
        Cart cart1 = cartService.sub(cart);
        return ResultInfo.success(cart1);
    }
    //清空
    @DeleteMapping("/cart/clean")
    public ResultInfo cleanCart(){

        cartService.cleanCart();

        return ResultInfo.success("null");
    }
}
